home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / mainsk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-07  |  8.3 KB  |  252 lines

  1.  
  2.        /*********************************************
  3.        *
  4.        *   file d:\cips\mainsk.c
  5.        *
  6.        *   Functions: This file contains
  7.        *      main
  8.        *
  9.        *   Purpose:
  10.        *      This file contains the main calling
  11.        *      routine that calls the erosion, dilation,
  12.        *      outline, and skeleton functions.
  13.        *
  14.        *   External Calls:
  15.        *      gin.c - get_image_name
  16.        *      numcvrt.c - get_integer
  17.        *                  int_convert
  18.        *      tiff.c - read_tiff_header
  19.        *      ed.c - erosion
  20.        *             dilation
  21.        *             mask_erosion
  22.        *             mask_dilation
  23.        *             interior_outline
  24.        *             exterior_outline
  25.        *             opening
  26.        *             closing
  27.        *      skeleton.c - thinning
  28.        *                   skeleton
  29.        *                   dilate_not_join
  30.        *                   special_opening
  31.        *                   special_closing
  32.        *                   edm
  33.        *                   mat
  34.        *
  35.        *   Modifications:
  36.        *      7 March 1993 - created
  37.        *
  38.        ***********************************************/
  39.  
  40. #include "cips.h"
  41.  
  42.  
  43.  
  44. short the_image[ROWS][COLS];
  45. short out_image[ROWS][COLS];
  46.  
  47. main(argc, argv)
  48.    int argc;
  49.    char *argv[];
  50. {
  51.  
  52.    char     name[80], name2[80], name3[80], type[80];
  53.    int      count, i, j,
  54.             il, ie, ll, le,
  55.             length, lw, mask_type, number,
  56.             threshold, width;
  57.    short    value;
  58.    struct   tiff_header_struct image_header;
  59.  
  60.    my_clear_text_screen();
  61.  
  62.        /*********************************************
  63.        *
  64.        *   Interpret the command line parameters.
  65.        *
  66.        **********************************************/
  67.  
  68.    if(argc < 5){
  69.     printf(
  70.     "\n\nNot enough parameters:"
  71.      "\n"
  72.      "\n usage: mainsk in-file out-file type value"
  73.      " [threshold-or-mask-type] [number]"
  74.      "\n"
  75.      "\n recall type: EROsion DILation Mask-ERosion"
  76.      "\n              Mask_DIlation INTerior-outline"
  77.      "\n              EXTerior-outline THInning"
  78.      "\n              Dilate-Not-Join OPEning"
  79.      "\n              CLOsing SPecial-Opening"
  80.      "\n              SPecial-Closing"
  81.      "\n              Euclidean-Distance-Measure"
  82.      "\n              Medial-Axis-Transform"
  83.      "\n"
  84.      "\n              [number] needed for opening"
  85.      "\n              and closing"
  86.      "\n");
  87.     exit(0);
  88.    }
  89.  
  90.    strcpy(name,     argv[1]);
  91.    strcpy(name2,    argv[2]);
  92.    strcpy(type,     argv[3]);
  93.    value     = atoi(argv[4]);
  94.    threshold = atoi(argv[5]);
  95.    mask_type = atoi(argv[5]);
  96.    number    = atoi(argv[6]);
  97.  
  98.    il = 1;
  99.    ie = 1;
  100.    ll = ROWS+1;
  101.    le = COLS+1;
  102.  
  103.        /*********************************************
  104.        *
  105.        *   Read the input image header and setup
  106.        *   the looping counters.
  107.        *
  108.        **********************************************/
  109.  
  110.    read_tiff_header(name, &image_header);
  111.  
  112.    length = (ROWS-10 + image_header.image_length)/ROWS;
  113.    width  = (COLS-10 + image_header.image_width)/COLS;
  114.    count  = 1;
  115.    lw     = length*width;
  116.    printf("\nlength=%d  width=%d", length, width);
  117.  
  118.        /*********************************************
  119.        *
  120.        *   Loop over the input images and
  121.        *   apply the desired function.
  122.        *
  123.        **********************************************/
  124.  
  125.    for(i=0; i<length; i++){
  126.       for(j=0; j<width; j++){
  127.          printf("\nrunning %d of %d", count, lw);
  128.          count++;
  129.  
  130.             /* thinning */
  131.          if(strncmp("thi", type, 3) == 0){
  132.             thinning(name, name2, the_image, out_image,
  133.                      il+i*ROWS, ie+j*COLS,
  134.                      ll+i*ROWS, le+j*COLS,
  135.                      value, threshold, 0);
  136.          }  /* ends thinning operation */
  137.  
  138.             /* dilate-not-join */
  139.          if(strncmp("dnj", type, 3) == 0){
  140.             dilate_not_join(name, name2, 
  141.                             the_image, out_image,
  142.                             il+i*ROWS, ie+j*COLS,
  143.                             ll+i*ROWS, le+j*COLS,
  144.                             value, threshold);
  145.          }  /* ends dilate_not_join operation */
  146.  
  147.             /* erosion */
  148.          if(strncmp("ero", type, 3) == 0){
  149.             erosion(name, name2, the_image, out_image,
  150.                     il+i*ROWS, ie+j*COLS,
  151.                     ll+i*ROWS, le+j*COLS,
  152.                     value, threshold);
  153.          }  /* ends erosion operation */
  154.  
  155.             /* dilation */
  156.          if(strncmp("dil", type, 3) == 0){
  157.             dilation(name, name2, the_image, out_image,
  158.                      il+i*ROWS, ie+j*COLS,
  159.                      ll+i*ROWS, le+j*COLS,
  160.                      value, threshold);
  161.          }  /* ends dilation operation */
  162.  
  163.             /* mask_erosion */
  164.          if(strncmp("mer", type, 3) == 0){
  165.             mask_erosion(name, name2, the_image,
  166.                          out_image, il+i*ROWS,
  167.                          ie+j*COLS, ll+i*ROWS,
  168.                          le+j*COLS, value, mask_type);
  169.          }  /* ends mask_erosion operation */
  170.  
  171.             /* mask_dilation */
  172.          if(strncmp("mdi", type, 3) == 0){
  173.             mask_dilation(name, name2, the_image,
  174.                           out_image, il+i*ROWS,
  175.                           ie+j*COLS, ll+i*ROWS,
  176.                           le+j*COLS, value, mask_type);
  177.          }  /* ends mask_dilation operation */
  178.  
  179.             /* interior_outline */
  180.          if(strncmp("int", type, 3) == 0){
  181.             interior_outline(name, name2, the_image,
  182.                              out_image, il+i*ROWS,
  183.                              ie+j*COLS, ll+i*ROWS,
  184.                              le+j*COLS, value,
  185.                              mask_type);
  186.          }  /* ends interior_outline operation */
  187.  
  188.             /* exterior_outline */
  189.          if(strncmp("ext", type, 3) == 0){
  190.             exterior_outline(name, name2, the_image,
  191.                              out_image, il+i*ROWS,
  192.                              ie+j*COLS, ll+i*ROWS,
  193.                              le+j*COLS, value,
  194.                              mask_type);
  195.          }  /* ends exterior_outline operation */
  196.  
  197.             /* opening */
  198.          if(strncmp("ope", type, 3) == 0){
  199.             opening(name, name2, the_image,
  200.                     out_image, il+i*ROWS,
  201.                     ie+j*COLS, ll+i*ROWS,
  202.                     le+j*COLS, value,
  203.                     mask_type, number);
  204.          }  /* ends opening operation */
  205.  
  206.             /* closing */
  207.          if(strncmp("clo", type, 3) == 0){
  208.             closing(name, name2, the_image,
  209.                     out_image, il+i*ROWS,
  210.                     ie+j*COLS, ll+i*ROWS,
  211.                     le+j*COLS, value,
  212.                     mask_type, number);
  213.          }  /* ends closing operation */
  214.  
  215.             /* special opening */
  216.          if(strncmp("spo", type, 3) == 0){
  217.             special_opening(name, name2, the_image,
  218.                             out_image, il+i*ROWS,
  219.                             ie+j*COLS, ll+i*ROWS,
  220.                             le+j*COLS, value,
  221.                             threshold, number);
  222.          }  /* ends special opening operation */
  223.  
  224.             /* special closing */
  225.          if(strncmp("spc", type, 3) == 0){
  226.             special_closing(name, name2, the_image,
  227.                             out_image, il+i*ROWS,
  228.                             ie+j*COLS, ll+i*ROWS,
  229.                             le+j*COLS, value,
  230.                             mask_type, number);
  231.          }  /* ends special closing operation */
  232.  
  233.             /* Euclidean Distance Measure */
  234.          if(strncmp("edm", type, 3) == 0){
  235.             edm(name, name2, the_image,
  236.                 out_image, il+i*ROWS,
  237.                 ie+j*COLS, ll+i*ROWS,
  238.                 le+j*COLS, value);
  239.          }  /* ends Euclidean distance mesaure */
  240.  
  241.             /* medial axis transform */
  242.          if(strncmp("mat", type, 3) == 0){
  243.             mat(name, name2, the_image,
  244.                 out_image, il+i*ROWS,
  245.                 ie+j*COLS, ll+i*ROWS,
  246.                 le+j*COLS, value);
  247.          }  /* ends medial axis transform operation */
  248.  
  249.       }  /* ends loop over j */
  250.    }  /* ends loop over i */
  251. }  /* ends main  */
  252.